package com.showde.shoppingmall.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.showde.shoppingmall.R;

public class ProgressDialog extends Dialog {

	private String title;
	private int contentViewId;
	private View contentView;
	private TextView titleTextView;

	private Activity activity;

	public ProgressDialog(Context context) {
		super(context);
		this.activity = (Activity) context;
	}

	public ProgressDialog(Context context, int theme) {
		super(context, R.style.dialogCustomer);
		this.activity = (Activity) context;
	}

	public ProgressDialog(Context context, String title, int contentViewId) {
		super(context, R.style.dialogCustomer);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.title = title;
		this.contentViewId = contentViewId;
		contentView = LayoutInflater.from(context).inflate(this.contentViewId,
				null);
		this.setContentView(contentView);
		this.setTitle(this.title);
		this.activity = (Activity) context;
		setViewFacade();
	}

	@Override
	public void setTitle(CharSequence title) {
		titleTextView = (TextView) contentView.findViewById(R.id.txt_title);
		titleTextView.setText(title);
	}

	private void setViewFacade() {
		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);

		WindowManager m = this.activity.getWindowManager();
		Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
		WindowManager.LayoutParams p = getWindow().getAttributes(); // 获取对话框当前的参数值

		// w:652
		// h:512
		p.height = (int) (d.getHeight() * 0.3); // 高度设置为屏幕的0.6
		p.width = (int) (d.getWidth() * 0.65); // 宽度设置为屏幕的0.95
		dialogWindow.setAttributes(p);
	}

}
